<template>
	<view class="container">
		<process :insflowid="process.InsFlowId" route="subject-gift-apply" :data="data" @confirm="confirm">
			<view class="container__card">
				<view class="container__card--form">
					<view class="container__card--form-label">审批编号</view>
					<view class="container__card--form-value">{{formatId(process.CreateTime)}}{{process.InsFlowId}}</view>
				</view>
				<view class="container__card--form">
					<view class="container__card--form-label">申请人</view>
					<view class="container__card--form-value">
						{{data.CreateUser}}
					</view>
				</view>
				<view class="container__card--form">
					<view class="container__card--form-label">礼品</view>
					<view class="container__card--form-value">
						{{data.GiftName}}
					</view>
				</view>
				<view class="container__card--form">
					<view class="container__card--form-label">规格</view>
					<view class="container__card--form-value">{{data.BatchScale}}</view>
				</view>
				<view class="container__card--form">
					<view class="container__card--form-label">描述</view>
					<view class="container__card--form-value">{{data.BatchDesc}}</view>
				</view>
				<view class="container__card--form">
					<view class="container__card--form-label">数量</view>
					<view class="container__card--form-value" style="color: #f5222d;font-weight: bold;font-size: 35rpx;">{{data.ApplyNum}}</view>
				</view>
			</view>
		</process>
	</view>
</template>

<script>
	import _custom from '@/common/_custom.js'
	import Process from '@/pages/home/child/add-attend/components/process.vue';
	
	export default {
		components: {
			Process,
		},
		data() {
			return {
				process: {},
				data: {}
			}
		},
		onLoad(options) {
			try {
				this.process = JSON.parse(options.data);
				console.log(this.process)
			} catch(e) {}
			this.getSubjectGiftApplyInfo()
		},
		onUnload() {
			uni.$off('process-confirm')
		},
		methods: {
			/**
			 * 获取礼品兑换详情
			 */
			getSubjectGiftApplyInfo() {
				let that = this;
				return new Promise((resolve,reject) => {
					_custom.getDataJava({
						apiname: 'getSubjectGiftApplyInfo',
						apiparam: {
							insflowid: this.process.InsFlowId,
						},
						success(res) {
							if(res.length) {
								that.data = res[0];
							}
						}
					})
				})
			},
			/**
			 * 加班折现申请通过
			 */
			subjectGiftPass(apiparam) {
				let that = this;
				return new Promise((resolve,reject) => {
					_custom.getDataJava({
						apiname: 'subjectGiftPass',
						code: 3,
						apiparam,
						success(res) {
							uni.showToast({
								title: '流程结束',
								icon: 'sucess'
							})
						}
					})
				})
			},
			/**
			 * 流程结束回调
			 * @param {Object} v
			 */
			confirm(v) {
				this.subjectGiftPass({
					insflowid: v.insflowid
				})
			},
			formatId(id) {
				try {
					id = id.replace(/-| |:/g, '')
				} catch {}
				return id
			},
		}
	}
</script>

<style scoped lang="scss">
	.container {
		position: relative;
		overflow-x: hidden;
		
		&__card {
			background-color: #fff;
			padding: 20rpx 30rpx;
			
			&--form {
				padding: 10rpx 0;
				
				&-label {
					color: #999;
					font-size: 28rpx;
				}
				
				&-value {
					font-size: 30rpx;
					white-space: pre-wrap;
					color: #555;
				}
			}
		}
	}
</style>
